%{
	#include <sstream>
	#include <iostream>
	
	#include "parser_list.h"
	
	using namespace std;
	using namespace krryn::parsers;
%}

%option noyywrap
%option case-insensitive
%option c++

NL			(\n|\r\n|\r)
ID			[a-z_][a-z0-9_-]*

/* yes this is yucky, it parses c-style comments */
COMMENT		\/\*[^*]*\*+([^/][^*]*\*+)*\/

%%

{COMMENT}	{return tok_list_comment;}
{ID}		{return tok_list_id;}
{NL}		{return tok_list_newline;}
"@"			{return tok_list_root;}
":"			{return tok_list_is;}
^\t+		{return tok_list_indent;}
","			{return tok_list_separator;}
"->"		{return tok_list_tada;}

%%

void parser_list::parse(std::istream &a_Input){
	yyFlexLexer l_Lexer;
	l_Lexer.switch_streams(&a_Input, 0);
	
	while(int l_Result = l_Lexer.yylex()){
		handle_token((tokens_list)l_Result, l_Lexer.YYText());
	}
	
	// because this parser looks ahead 1 character
	// we need to call handle_token one extra time
	// to make sure that the last token is also 
	// processed.
	handle_token(tok_list_end, "");
}